home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
ACKSRC.ZIP
/
MAPEDIT.C
< prev
next >
Wrap
Text File
|
1993-06-20
|
26KB
|
1,298 lines
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <mem.h>
#include <alloc.h>
#include <io.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <sys\stat.h>
#include "ack3d.h"
#include "mapedit.h"
RECT HotSpots[] = {
1,25,161,153, /* 0 Main grid */
163,23,172,32, /* 1 Up arrow */
163,146,172,155, /* 2 Dn arrow */
0,155,11,164, /* 3 Lt arrow */
152,155,163,164, /* 4 Rt arrow */
186,2,196,130, /* 5 1st wall */
198,2,208,130, /* 6 2nd wall */
210,2,220,130, /* 7 3rd wall */
222,2,232,130, /* 8 4th wall */
259,2,269,130, /* 9 1st obj */
271,2,281,130, /* 10 2nd obj */
283,2,293,130, /* 11 3rd obj */
295,2,305,130, /* 12 4th obj */
4,173,37,185, /* 13 Load */
41,173,75,185, /* 14 Save */
134,173,163,185, /* 15 Exit */
241,22,251,30, /* 16 blank sq */
243,2,249,8, /* 17 Pass box */
80,173,112,185, /* 18 New */
241,41,251,49, /* 19 Start box */
241,62,251,70, /* 20 Up box */
241,83,251,91, /* 21 Dn box */
241,103,251,111, /* 22 Goal box */
-1,-1,-1,-1
};
unsigned char far *ScreenBuffer;
unsigned char Grid[4096];
unsigned char *bMaps[256];
unsigned char *oMaps[256];
char GridFile[128];
char PalFile[128];
unsigned char Palette[768];
int GridX;
int GridY;
int CurrentType;
int CurrentSquare;
int PassFlag;
int ModifiedFlag;
int ErrorCode;
unsigned char *WallSquares[256];
unsigned char *ObjSquares[256];
unsigned char ObjbmNum[256];
RECT WallCoords[] = {
186,2,196,130, /* 1st wall */
198,2,208,130, /* 2nd wall */
210,2,220,130, /* 3rd wall */
222,2,232,130 /* 4th wall */
};
RECT ObjCoords[] = {
259,2,269,130, /* 1st obj */
271,2,281,130, /* 2nd obj */
283,2,293,130, /* 3rd obj */
295,2,305,130 /* 4th obj */
};
RECT SpecialActions[] = {
241,41,251,49, /* Start box */
241,62,251,70, /* Up box */
241,83,251,91, /* Dn box */
241,103,251,111 /* Goal box */
};
#define TOTAL_SPECIAL 4
unsigned char Pal0[] = {0,0,0,0,0,0x2A,0,0x2A,0};
unsigned char Pal11[] = {0x15,0x3f,0x3f,0x3f,0x15,0x15,
0x3f,0x15,0x3f};
unsigned char Pal15[] = {0x3f,0x3f,0x3f,0x3b,0x3b,0x3b,0x37,
0x37,0x37};
BOXES MsgBox[] = {
82,48,"mapbox1",1,1,136,81,161,93,0,0,0,0,0,0,0,0,0,0,0,0,
61,49,"mapbox2",1,2,101,87,132,101,166,87,197,101,0,0,0,0,0,0,0,0,
61,49,"mapbox3",1,2,101,87,132,101,166,87,197,101,0,0,0,0,0,0,0,0,
97,54,"mapbox4",0,1,130,88,151,100,0,0,0,0,0,0,0,0,0,0,0,0,
82,48,"mapbox5",1,1,136,81,161,93,0,0,0,0,0,0,0,0,0,0,0,0,
82,48,"mapbox6",1,1,136,81,161,93,0,0,0,0,0,0,0,0,0,0,0,0,
};
unsigned char far * Readiff(char *picname);
/****************************************************************************
** **
****************************************************************************/
void SoundBeep(void)
{
sound(440);
delay(50);
nosound();
}
/****************************************************************************
** **
****************************************************************************/
void ScreenToBuffer(int x,int y,int wt,int ht,unsigned char *Buffer)
{
int row;
unsigned char *Video;
Video = MK_FP(0xA000,(y * 320) + x);
for (row = 0; row < ht; row++)
{
memmove(Buffer,Video,wt);
Buffer += wt;
Video += 320;
}
}
/****************************************************************************
** **
****************************************************************************/
void BufferToScreen(int x,int y,int wt,int ht,unsigned char *Buffer)
{
int row;
unsigned char *Video;
Video = MK_FP(0xA000,(y * 320) + x);
for (row = 0; row < ht; row++)
{
memmove(Video,Buffer,wt);
Buffer += wt;
Video += 320;
}
}
/****************************************************************************
** **
****************************************************************************/
int ShowMsgBox(int Number)
{
int i,handle,len,result;
int mx,my,mButton;
int x,y,wt,ht;
char *BackBuffer;
char *BoxBuffer;
char size[4];
char fName[14];
strcpy(fName,MsgBox[Number].FileName);
AddExtent(fName,".bbm");
BoxBuffer = Readiff(fName);
if (BoxBuffer == NULL)
return(0);
wt = (*(int *)BoxBuffer);
ht = (*(int *)&BoxBuffer[2]);
len = wt * ht;
BackBuffer = malloc(len);
if (BackBuffer == NULL)
{
free(BoxBuffer);
return(0);
}
#if 0
handle = open(fName,O_RDWR|O_BINARY);
if (handle < 1)
return(0);
read(handle,size,4);
ht = (*(int *)size);
wt = (*(int *)&size[2]);
len = wt * ht;
BackBuffer = malloc(len);
BoxBuffer = malloc(len);
if (BackBuffer == NULL || BoxBuffer == NULL)
{
close(handle);
return(0);
}
read(handle,BoxBuffer,len);
close(handle);
#endif
x = MsgBox[Number].BoxX;
y = MsgBox[Number].BoxY;
mouse_hide_cursor();
ScreenToBuffer(x,y,wt,ht,BackBuffer);
BufferToScreen(x,y,wt,ht,&BoxBuffer[4]);
mouse_show_cursor();
if (MsgBox[Number].DoBeep)
SoundBeep();
len = 0;
while (!len)
{
if (inkey() == 0x1C0D)
break;
mouse_read_cursor(&mButton,&my,&mx);
if (mButton & 1)
{
for (i = 0; i < MsgBox[Number].NumButtons; i++)
{
if (mx >= MsgBox[Number].ButtonCoords[i].x &&
mx <= MsgBox[Number].ButtonCoords[i].x1 &&
my >= MsgBox[Number].ButtonCoords[i].y &&
my <= MsgBox[Number].ButtonCoords[i].y1)
{
result = i;
mouse_released();
len = 1;
break;
}
}
}
}
mouse_hide_cursor();
BufferToScreen(x,y,wt,ht,BackBuffer);
mouse_show_cursor();
free(BackBuffer);
free(BoxBuffer);
return(result);
}
/****************************************************************************
** **
****************************************************************************/
int GetAction(int mx,int my)
{
int i = 0;
while (1)
{
if (HotSpots[i].x < 0)
return(-1);
if (mx >= HotSpots[i].x &&
mx <= HotSpots[i].x1 &&
my >= HotSpots[i].y &&
my <= HotSpots[i].y1)
break;
i++;
}
return(i);
}
/****************************************************************************
** **
****************************************************************************/
void ShowScreen(void)
{
unsigned char far *Video;
Video = MK_FP(0xA000,0);
memmove(Video,ScreenBuffer,64000);
}
/****************************************************************************
** **
****************************************************************************/
void GetBufferSquare(int x,int y,unsigned char *buffer)
{
int row;
unsigned char *src;
src = ScreenBuffer + ((y * 320) + x);
for (row = 0; row < 8; row++)
{
memmove(buffer,src,10);
buffer += 10;
src += 320;
}
}
/****************************************************************************
** **
****************************************************************************/
int BuildSquares(void)
{
int i,j,x,y,num;
unsigned char *Square;
Square = malloc(80);
if (Square == NULL)
{
ErrorCode = ERR_NOMEMORY;
return(-1);
}
WallSquares[0] = Square;
GetBufferSquare(1,25,Square);
num = 1;
for (i = 0; i < 4; i++)
{
x = WallCoords[i].x;
y = WallCoords[i].y;
for (j = 0; j < 16; j++)
{
Square = malloc(80);
if (Square == NULL)
return(-1);
WallSquares[num++] = Square;
GetBufferSquare(x,y,Square);
y += 8;
}
}
num = 1;
for (i = 0; i < 4; i++)
{
x = ObjCoords[i].x;
y = ObjCoords[i].y;
for (j = 0; j < 16; j++)
{
Square = malloc(80);
if (Square == NULL